<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #text{
      color: #999;
    }
  </style>
</head>
<body>
  <input id="text" type="text" value="请输入搜索关键字">
  <input type="button" value="搜索">
  <script>
    //获取元素
    var textIpt = document.getElementById("text");

    //获得焦点
    textIpt.onfocus = function(){
      if(this.value == "请输入搜索关键字"){
        this.value = "";
        textIpt.style.color = "#000";
      }else{
        textIpt.style.color = "#000";
      }
    }
    //失去焦点
    textIpt.onblur = function(){
      if(this.value == "" || this.value == "请输入搜索关键字"){
        this.value = "请输入搜索关键字";
        textIpt.style.color = "#999";
      }
    }
  </script>
</body>
</html>